﻿using OnlineAuction.DataAccess;
using OnlineAuction.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace OnlineAuction.Business
{
    public class CategoryBO
    {
        public List<CategoryE> GetCategory()
        {
            //Get all category
            List<CategoryE> list = new List<CategoryE>();
            CategoryDA da = new CategoryDA();
            DataSet ds = da.GetCategory();
            list.Add(new CategoryE(0, ""));
            //Convert dataset to list category
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                list.Add(new CategoryE(int.Parse(row["CategoryID"].ToString()),
                    row["CategoryName"].ToString()));
            }
            return list;
        }

        public bool AddItems(CategoryE category)
        {
            //Add new category
            CategoryDA da = new CategoryDA();
            return da.AddItems(category);
        }

        public bool MergeCategory(CategoryE ce1, CategoryE ce2, string categoryName)
        {
            //Add new category
            CategoryDA da = new CategoryDA();
            return da.MergeCategory(ce1, ce2, categoryName); ;
        }

        public List<CategoryE> ViewCategorys()
        {
            List<CategoryE> list = new List<CategoryE>();
            CategoryDA da = new CategoryDA();
            DataSet ds = da.ViewCategorys();
            //Convert dataset to list category
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                list.Add(new CategoryE(int.Parse(row["CategoryID"].ToString()),
                    row["CategoryName"].ToString(), row["CategoryLogo"].ToString(),
                    bool.Parse(row["CategoryState"].ToString())));
            }
            return list;
        }
        public bool DelelteCategory(int CategoryID)
        {
            //Delete category
            CategoryDA da = new CategoryDA();
            return da.DelelteCategory(CategoryID);
        }

        public bool UpdateCategory(CategoryE category)
        {
            //Update category
            CategoryDA da = new CategoryDA();
            return da.UpdateCategory(category);
        }

        public CategoryE GetCategoryForID(int CategoryID)
        {
            CategoryE ce = new CategoryE(CategoryID);
            CategoryDA da = new CategoryDA();
            DataSet ds = da.GetCategoryForID(CategoryID);
            //Convert dataset to category
            DataRow row = ds.Tables[0].Rows[0];
            ce = new CategoryE(int.Parse(row["CategoryID"].ToString()),
                    row["CategoryName"].ToString(), row["CategoryLogo"].ToString(),
                    bool.Parse(row["CategoryState"].ToString()));
            return ce;
        }
    }
}
